/**
 * @(#) VacationListProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	휴가/근무 리스트 Proxy - Proxy
 * 				휴가/근무 리스트를 기간별로 조회
 */
package com.skt.common_hr.work_sac.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.work_sac.WorkFacade;
	import com.skt.common_hr.work_sac.model.vo.VacationVO;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
		
	public class VacationListProxy extends CommonProxy
	{
		public static const NAME:String = "VacationListProxy";
		
		public var holidayList:ArrayCollection;
		public var vacationList:ArrayCollection;
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function VacationListProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, from:Date, toDate:Date):void
		{
			var param:Object = new Object();
			param["I_PERNR"] 	= pernr;
			param["I_BEGDA"]	= DateUtil.toBasicString(from);
			param["I_ENDDA"]	= DateUtil.toBasicString(toDate);
			param["I_WGBN"]		= "";
			param["I_DGBN"]		= "";
			trace(pernr+", " + param["I_BEGDA"]+", " + param["I_ENDDA"]);
			loadData("Z_HR_0024", param, result, fault); 
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {  
				vacationList = parseVacationList(event.result.CALTAB2);
				facade.sendNotification(WorkFacade.LOAD_VACATIONLIST_COMPLETE, this);
			}
			else {
				facade.sendNotification(WorkFacade.LOAD_VACATIONLIST_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(WorkFacade.LOAD_VACATIONLIST_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 제증명서 종류 Code list
		 */
		private function parseVacationList(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			for each(var rec:Object in srcArr) 
			{
				var vo:VacationVO = new VacationVO();
				vo.WGBN 		= rec["WGBN"];
				vo.WGBNT		= rec["WGBNT"];
				vo.DGBN			= rec["DGBN"];
				vo.DGBNT		= rec["DGBNT"];
				vo.AWART		= rec["AWART"];
				vo.AWATX		= rec["AWATX"];
				vo.BEGDA		= DateUtil.stringToDateTime(rec["BEGDA"]);
				vo.ENDDA		= DateUtil.stringToDateTime(rec["ENDDA"]);
				vo.BEGUZ		= DateUtil.stringToDateTime(rec["BEGUZ"]);
				vo.ENDUZ		= DateUtil.stringToDateTime(rec["ENDUZ"]);
				vo.WSTATUS		= rec["WSTATUS"];
				vo.WSTATX		= rec["WSTATX"];
				vo.TABNR		= rec["TABNR"];
				vo.TEXT1			= rec["TEXT1"];
				vo.OT011		= rec["OT011"];
				vo.OT012		= rec["OT012"];
				vo.OT021		= rec["OT021"];
				vo.OT022		= rec["OT022"];
				vo.OT023		= rec["OT023"];
				retArr.addItem(vo);
			}
			return retArr;	
		}
		
	}
}